<template>
  <el-row justify="center" style="overflow: hidden;">
    <div class="wave">
      <span></span>
      <span></span>
      <span></span>
    </div>
    <el-col :span="12" class="hoverFilter al-relative">
      <div class="filterContent al-flex al-flex-column al-absolute al-w al-align-items"
        style="row-gap: 24px;transform: translateY(100px);"
      >
        <div v-for="(skill, index) in skills" :key="skill.id" class="al-flex al-align-items">
          <strong class="al-size-32 al-m-r-20 textShadow" :class="`textGradient-${(index)%4}`">
            {{ skill.title }}
          </strong>
          <span v-if="skill.id === 'Element-Plus'">
            <el-icon :size="40" color="#1a86f9"><ElementPlus /></el-icon>
          </span>
          <Icon v-else-if="skill.icon" :icon="skill.icon" class="al-size-40" />
          <el-image v-else style="height: 40px;width:40px;" :src="svg_chromajs" />
        </div>
      </div>
      <!-- <el-image :src="svg_robotUrl" fit="cover" style="position: absolute;" class="imageFilter al-w al-h animate__animated animate__bounceIn" /> -->
      <el-image :src="logo" fit="fill" class="imageFilter al-w" />
      <el-form
        ref="ruleFormRef"
        :model="ruleForm"
        :rules="rules"
        label-width="0px"
        status-icon
        class="al-m-40"
      >
        <el-form-item prop="account" class="animate__animated animate__bounceIn animate__delay-1s">
          <el-input v-model="ruleForm.account"
            :prefix-icon="User" />
        </el-form-item>
        <el-form-item prop="password" class="animate__animated animate__bounceIn animate__delay-1s">
          <el-input
            v-model="ruleForm.password"
            type="password"
            placeholder="Please input password"
            show-password
            :prefix-icon="Lock"
          />
        </el-form-item>
        <el-form-item class="content-center animate__animated animate__bounceIn animate__delay">
          <el-button class="a-button hoverButton" type="success" @click="submitForm(ruleFormRef)">
            {{ t('buttons.login') }}
          </el-button>
          <el-button class="a-button hoverButton" type="primary" @click="resetForm(ruleFormRef)">
            {{ t('buttons.world') }}
          </el-button>
        </el-form-item>
      </el-form>
    </el-col>
  </el-row>
</template>

<script lang="ts" setup>
import {
  User,
  Lock,
  ElementPlus
} from '@element-plus/icons-vue'
import { reactive, ref } from 'vue'
import { useRouter } from "vue-router"
import { useI18n } from 'vue-i18n'
import type { FormInstance, FormRules } from 'element-plus'
import { usePermissionStore } from '@/stores/modules/permission'
import { inject } from 'vue';
import svg_chromajs from '@/assets/svg/chroma.js.svg?url'
import { OPP } from '../world/docs'

const utils: any = inject('utils')
const logo = utils.getAssetsFile('assets/images/login/', 'algate', 'gif')

const skills = OPP.doc

const { t } = useI18n();

interface RuleForm {
  account: string
  password: string
}
const ruleFormRef = ref<FormInstance>()
const ruleForm = reactive<RuleForm>({
  account: 'algate',
  password: '123456'
})
const rules = reactive<FormRules<RuleForm>>({
  account: [
    { required: true, message: 'Please input Activity name', trigger: 'blur' },
    { min: 3, max: 20, message: 'Length should be 3 to 5', trigger: 'blur' },
  ],
  password: [
    { required: true, message: 'Please input password', trigger: 'blur' },
  ]
})

// 登录
const router = useRouter()
const submitForm = async (formEl: FormInstance | undefined) => {
  if (!formEl) return
  await formEl.validate((valid, fields) => {
    if (valid) {
      const { isLogin, setLogin } = usePermissionStore()
      setLogin()
      isLogin && router.push({path: '/home', replace: true})
    } else {
      console.log('error submit!', fields)
    }
  })
}

const resetForm = (formEl: FormInstance | undefined) => {
  if (!formEl) return
  formEl.resetFields()
  router.push({path: '/world'})
}
</script>
<style lang="scss" scoped>
.animate__animated.animate__bounceIn {
  --animate-duration: 2s;
}

.content-center {
  height: 32px;
  .el-form-item__content {
    position: relative;
    align-content: center;
    .el-button {
      flex: 1;
    }
  }
}
:deep(.el-input__wrapper) {
  // background-color: transparent;
  background-color: rgba(0, 0, 0, 0.1);
  border-radius: unset;
  .el-input__inner,
  .el-input__icon {
    color: #fff;
  }
}
:deep(.el-button).a-button {
  border-radius: unset;
}
:deep(.el-space) > span {
  color: var(--el-color-info-light-3);
}
.textShadow {
  // text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
}
.hoverFilter {
  .imageFilter {
    filter: blur(20px);
    opacity: 0;
    transition: 1s;
  }
  .el-form {
    filter: blur(2px);
    opacity: 0.6;
    transition: 1s;
    transform: translateY(60px);
  }
  .filterContent {
    z-index: 1;
    filter: blur(0);
    opacity: 1;
    transform: scale(1);
    transition: 1s;
  }
}
.hoverFilter {
  &:hover {
    .el-form,
    .imageFilter {
      filter: blur(0);
      opacity: 1;
      transform: scale(1);
    }
    .filterContent {
      z-index: 0;
      filter: blur(20px);
      opacity: 0.1;
      transform: scale(0.5);
    }
  }
}

.el-row {
  position: relative;
  height: 100vh;
  width: 100%;
}
.el-row .wave{
  position: absolute;
  width: 100%;
  height: 100%;
}

.el-row .wave span{
  position: absolute;
  width: 325vh;
  height: 325vh;
  left: 50%;
  transform: translate(-50%, -75%);
  opacity: 0.8;
  // mix-blend-mode CSS 属性描述了元素的内容应该与元素的直系父元素的内容和元素的背景如何混合。
  mix-blend-mode: multiply;
}
.el-row .wave span:nth-child(1) {
  animation: animate 5s linear infinite;
  border-radius: 45%;
  background: linear-gradient(#f403d1, #64b5f6);
}
.el-row .wave span:nth-child(2) {
  animation: animate 10s linear infinite;
  border-radius: 40%;
  background: linear-gradient(#ffec61, #f321d7);
}
.el-row .wave span:nth-child(3) {
  animation: animate 15s linear infinite;
  border-radius: 42.5%;
  background: linear-gradient(#24ff72, #2196f3);
}

@keyframes animate{
  0%{
    transform: translate(-50%, -75%) rotate(0deg);
  }
  100%{
    transform: translate(-50%, -75%) rotate(360deg);
  }
}

// 按钮特效
.hoverButton {
  font-weight: 600;
  position: absolute;
  margin-left: 0;
  left: 0;
  right: 0;
}

.hoverButton:nth-child(2) {
  overflow: hidden;
  transition: 0.5s;
  clip-path: polygon(50% 0%, 100% 0%, 100% 100%,50% 100%, 53% 50%);
  justify-content: flex-end;
}
.hoverButton:nth-child(1) {
  justify-content: flex-start;
}

.hoverButton:nth-child(2):hover {
  clip-path: polygon(25% 0, 100% 0%, 100% 100%, 25% 100%, 22% 50%);
  justify-content: center;
}

.hoverButton:nth-child(1):hover {
  justify-content: center;
}

/* 后续兄弟选择器（所有兄弟） ~ 此处也可以用兄弟选择器 + */ 
/* .hoverButton:nth-child(1):hover ~ span:nth-child(2) { */
.hoverButton:nth-child(1):hover + .hoverButton {
  clip-path: polygon(75% 0, 100% 0%, 100% 100%, 75% 100%, 78% 50%);
  justify-content: center;
}
</style>
